package wangm.util;

import java.util.Random;
import java.util.UUID;

/**
 * describe
 *
 * @author zk
 * @date 2018-02-23 14:17
 */
public class StringsUtils {
    /**
     * 生成32位随机字符串
     *
     * @return uuid string
     */
    public static String randomUUidString(){
        String result = UUID.randomUUID().toString().replace("-","");
        if(result.length() > 32){
            result = result.substring(0,32);
        }
        return result;
    }

    /**
     * 随机字符
     *
     * @param number 字符个数
     * @return 随机的字符串
     */
    public static String randomCharacter(int number){
        Character[] character = {'A','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R','S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
                ,'a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r','s', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
        StringBuffer result = new StringBuffer("");
        Random random = new Random();
        for (int i = 0; i < number; i++) {
            result.append(character[random.nextInt(48)]);
        }
        return result.toString();
    }
}
